package com.littcore.saap.core.module.message;

import java.io.Serializable;
import java.util.Date;


/**
 * 基础消息.
 * 
 * <pre><b>描述：</b>
 *    消息的基本结构
 * </pre>
 * 
 * <pre><b>修改记录：</b>
 *    
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">蔡源</a>
 * @since 2015年10月27日
 * @version 1.0
 */
public class BaseMessage implements Serializable, Cloneable {

  /** The Constant serialVersionUID. */
  private static final long serialVersionUID = 1L;
  
  private String domainCode;
  private String moduleCode;
  private String messageCode;
  
  /** 业务记录ID(记录模式消息必填). */
  private int recordId;
  
  private int tenantId;
  
  /** 
   * 消息发送者.
   * 系统发送时为0
   */
  private int fromBy;
  /** 消息接收者. */
  private int receiveBy;
  
  /** 消息关注者. */
  //private int followBy;
  
  private Date createDatetime;
  
  /** 
   * 是否强制发送.
   * 某些消息通过指定强制发送可在用户未订阅的情况下进行发送
   */
  private boolean fourced;
    
  /**
   * @param domainCode
   * @param moduleCode
   * @param messageCode
   */
  public BaseMessage(String domainCode, String moduleCode, String messageCode, int tenantId)
  {
    this(domainCode, moduleCode, messageCode, tenantId, 0);
  }
  
  public BaseMessage(String domainCode, String moduleCode, String messageCode, int tenantId, int recordId)
  {
    this.domainCode = domainCode;
    this.moduleCode = moduleCode;
    this.messageCode = messageCode;
    this.tenantId = tenantId;
    this.recordId = recordId;
    this.createDatetime = new Date();
  }
  
  public String getMetaCode()
  {
    return this.domainCode +"-"+this.moduleCode+"-"+this.messageCode;
  }
  
  /**
   * @return the moduleCode
   */
  public String getModuleCode()
  {
    return moduleCode;
  }

  
  /**
   * @param moduleCode the moduleCode to set
   */
  public void setModuleCode(String moduleCode)
  {
    this.moduleCode = moduleCode;
  }

  
  /**
   * @return the messageCode
   */
  public String getMessageCode()
  {
    return messageCode;
  }

  
  /**
   * @param messageCode the messageCode to set
   */
  public void setMessageCode(String messageCode)
  {
    this.messageCode = messageCode;
  }

  
  /**
   * @return the createDatetime
   */
  public Date getCreateDatetime()
  {
    return createDatetime;
  }

  
  /**
   * @param createDatetime the createDatetime to set
   */
  public void setCreateDatetime(Date createDatetime)
  {
    this.createDatetime = createDatetime;
  }


  
  /**
   * @return the domainCode
   */
  public String getDomainCode()
  {
    return domainCode;
  }


  
  /**
   * @param domainCode the domainCode to set
   */
  public void setDomainCode(String domainCode)
  {
    this.domainCode = domainCode;
  }


  
  /**
   * @return the receiveBy
   */
  public int getReceiveBy()
  {
    return receiveBy;
  }


  
  /**
   * @param receiveBy the receiveBy to set
   */
  public void setReceiveBy(int receiveBy)
  {
    this.receiveBy = receiveBy;
  }


  
  /**
   * @return the fromBy
   */
  public int getFromBy()
  {
    return fromBy;
  }


  
  /**
   * @param fromBy the fromBy to set
   */
  public void setFromBy(int fromBy)
  {
    this.fromBy = fromBy;
  }

  
  /**
   * @return the tenantId
   */
  public int getTenantId()
  {
    return tenantId;
  }

  
  /**
   * @param tenantId the tenantId to set
   */
  public void setTenantId(int tenantId)
  {
    this.tenantId = tenantId;
  }

  
  /**
   * @return the recordId
   */
  public int getRecordId()
  {
    return recordId;
  }

  
  /**
   * @param recordId the recordId to set
   */
  public void setRecordId(int recordId)
  {
    this.recordId = recordId;
  }

  
  /**
   * @return the fourced
   */
  public boolean isFourced()
  {
    return fourced;
  }

  
  /**
   * @param fourced the fourced to set
   */
  public void setFourced(boolean fourced)
  {
    this.fourced = fourced;
  }

  
//  /**
//   * @return the followBy
//   */
//  public int getFollowBy()
//  {
//    return followBy;
//  }
//
//  
//  /**
//   * @param followBy the followBy to set
//   */
//  public void setFollowBy(int followBy)
//  {
//    this.followBy = followBy;
//  }

  /* (non-Javadoc)
   * @see java.lang.Object#clone()
   */
  @Override
  public BaseMessage clone() 
  {
    try
    {
      return (BaseMessage)super.clone();
    } catch (CloneNotSupportedException e)
    {
      throw new RuntimeException(e);
    }
  }
  
}
